-- load lib socket
local socket = require "socket"

-- some configuration
host = "www.lua.org"
file = "/manual/5.3/manual.html"

-- build a tcp connect
c = assert(socket.connect(host, 80))

-- send a request to download the file
local request = string.format(
	"GET %s HTTP/1.0\r\nhost: %s\r\n\r\n", file, host)
c:send(request)

-- read data and write it into stdout
repeat
	local s, status, partial = c:receive(2^10) 	-- 1kb
	io.write(s or partial)
until status == "closed"

-- close the connect
c:close()
